package ao.com.bna.dao;

import java.util.List;

import org.hibernate.Session;


/**
 * @author Domingos Razao Fancone
 * 
 * @param <T>
 */
public abstract class AbstractHibernateDao<T> {
	private Class<T> entityClass;

	/**
	 * @param entityClass
	 */
	public AbstractHibernateDao(Class<T> entityClass) {
		this.entityClass = entityClass;
	}

	protected abstract Session getSession();

	public void gravar(T entity) {
		getSession().saveOrUpdate(entity);
	}

	public void remover(T entity) {
		getSession().delete(entity);
	}

	public T obterPorID(Long id) {
		return (T)getSession().get(entityClass, id);
	}

	public List<T> listar() {
		return (List<T>)getSession().createCriteria(entityClass).list();
	}

}
